package com.revenant.driver.adapter;

import android.util.Log;
import android.view.View;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.appcompat.widget.AppCompatRadioButton;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chad.library.adapter.base.entity.IExpandable;
import com.chad.library.adapter.base.entity.MultiItemEntity;
import com.google.android.material.checkbox.MaterialCheckBox;
import com.revenant.driver.R;
import com.revenant.driver.bean.AreaShowBean;
import com.revenant.driver.bean.selectcarnumber.StatusNormalBean;
import com.revenant.driver.bean.selectcarnumber.StatusNormalSecondBean;
import com.revenant.driver.bean.selectcarnumber.StatusTabbeddNormalBean;
import com.revenant.driver.bean.selectcarnumber.StatusTabbeddNormalSecondBean;

import java.util.List;

import static com.blankj.utilcode.util.ColorUtils.getColor;

/**
 * @ProjectName: Shipper
 * @Package: com.revenant.shipper.adapter
 * @ClassName: MineBigItemAdapter
 * @Description: java类作用描述
 * @Author: revenant
 * @CreateDate: 2019-12-30 14:18
 * @UpdateUser: 更新者
 * @UpdateDate: 2019-12-30 14:18
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
public class SelectCarNumberNewBeanAdapter extends BaseMultiItemQuickAdapter<MultiItemEntity, BaseViewHolder> {

    private static final String TAG = SelectCarNumberNewBeanAdapter.class.getSimpleName();

    public static final int TYPE_LEVEL_0 = 0;
    public static final int TYPE_LEVEL_1 = 1;
    public static final int TYPE_LEVEL_0_Second = 2;
    public static final int TYPE_LEVEL_1_Second = 3;

    private boolean isOnlyExpandOne = true;

    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param data A new list is created out of this one to avoid mutable list
     */
    public SelectCarNumberNewBeanAdapter(List<MultiItemEntity> data) {
        super(data);
        addItemType(TYPE_LEVEL_0, R.layout.item_select_car_number_one);
//        addItemType(TYPE_LEVEL_0_Second, R.layout.item_select_car_number_one_second);
        addItemType(TYPE_LEVEL_1, R.layout.item_select_car_number_two_sesond);
        addItemType(TYPE_LEVEL_1_Second, R.layout.item_select_car_number_two);

    }


    @Override
    protected void convert(@NonNull final BaseViewHolder holder, final MultiItemEntity item) {
        switch (holder.getItemViewType()) {
            case TYPE_LEVEL_0:
                StatusNormalSecondBean lv0 = (StatusNormalSecondBean) item;
                holder.setText(R.id.car_num, lv0.cardNumber);
                switch (lv0.carstatus) {
                    case 0:
                        holder.setText(R.id.car_type, "空闲中")
                                .setTextColor(R.id.car_type,getColor(R.color.blue));
                        holder.setVisible(R.id.check_select,true);

                        MaterialCheckBox appCompatRadioButton = holder.getView(R.id.check_select);
                        if (((StatusNormalSecondBean) item).isIsselect()) {
                            appCompatRadioButton.setChecked(true);
                        } else {
                            appCompatRadioButton.setChecked(false);

                        }

                        holder.addOnClickListener(R.id.check_select);

                        break;
                    case 1:
                        holder.setText(R.id.car_type, "忙碌中")
                                .setTextColor(R.id.car_type,getColor(R.color.red));
                        holder.setVisible(R.id.check_select,false);
                        break;
                }

                holder.itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        int pos = holder.getAdapterPosition();
                        if (lv0.isExpanded()) {
                            collapse(pos);
                        } else if (isOnlyExpandOne) {
                            IExpandable willExpandItem = (IExpandable) getData().get(pos);
                            for (int i = getHeaderLayoutCount(); i < getData().size(); i++) {
                                IExpandable expandable = (IExpandable) getData().get(i);
                                if (expandable.isExpanded()) {
                                    collapse(i);
                                }
                            }
                            expand(getData().indexOf(willExpandItem) + getHeaderLayoutCount());
                        } else {
                            expand(pos);
                        }
                    }
                });

                break;
//            case TYPE_LEVEL_0_Second:
//                StatusNormalSecondBean lv1=(StatusNormalSecondBean)item;
//                holder.setText(R.id.car_num_second, lv1.cardNumber);
//                break;
            case TYPE_LEVEL_1:

                StatusTabbeddNormalBean lv3 = (StatusTabbeddNormalBean) item;
                switch (lv3.status){
                    case 0:
                        holder.setText(R.id.car_num_tab, lv3.carinfo);
                        holder.setText(R.id.car_head_or, lv3.isTrailerCarInfo==0?"头车信息":"挂车信息");
                        break;
                }

                break;
            case TYPE_LEVEL_1_Second:
                StatusTabbeddNormalBean lv2 = (StatusTabbeddNormalBean) item;
                switch (lv2.status){
                    case 1:
                        holder.setText(R.id.username, lv2.driverName);
                        holder.setText(R.id.time, lv2.ordertime);
                        holder.setText(R.id.car_head_or, lv2.isTrailerCarInfo==0?"头车信息":"挂车信息");
                        holder.setText(R.id.car_num_second, lv2.carinfo);
                        Glide.with(mContext).load(lv2.imageUrl).placeholder(R.mipmap.picture).centerCrop().
                                into((ImageView) holder.getView(R.id.imgae));
                        holder.addOnClickListener(R.id.callphone);
                        break;
                }


                break;
            default:
                break;
        }
    }

    public boolean isOnlyExpandOne() {
        return isOnlyExpandOne;
    }

    public void setOnlyExpandOne(boolean onlyExpandOne) {
        isOnlyExpandOne = onlyExpandOne;
    }
}
